<?php
// google guide
// https://developers.google.com/youtube/2.0/developers_guide_protocol?hl=ja
// google oauth playground api
// https://developers.google.com/oauthplayground/?code=4/9FEOf1uFPWw0Qy7JmsuSXgQDMGfv.ot0e8kw5_V0dgrKXntQAax1mbK6ifAI
//https://code.google.com/apis/ajax/playground/?exp=youtube#change_the_playing_video
require_once 'Zend/Loader.php';
require_once ("../library/UserAgentManager.class.php");
require_once ("../library/FeedUtil.class.php");
require_once ("/virtual/twotiger/lib/library/SecureManager.class.php");
session_start();
header("Access-Control-Allow-Origin: *");
//$frontController = Zend_Controller_Front::getInstance();
//$appConfig = $frontController->getParam('bootstrap')->getOptions();
//var_export($appConfig);
$userAgentManager = new UserAgentManager();
$is_smartphone = $userAgentManager->is_smartphone();
$feedUtil = new FeedUtil();
$secureManager = new SecureManager();

$videoid ='NZktTKwEjtc';

if(isset($_GET['videoid'])){
  $videoid = $secureManager->sanitize($_GET['videoid']);
}

?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="youtube player">
<meta name="description" content="youtube player">
<meta name="author" content="ken kodama">
<title>player</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script language="JavaScript">
$.mobile.ajaxEnabled = false;
</script>
<script type="text/javascript">
google.load("swfobject", "2.1");
</script>
<script type="text/javascript">
var global_video_id = "<?php echo $videoid;?>";
var player = null;

function initloadPlayer() {
    fGetScript();
}
function fGetScript() {
    $.ajax({
        url: "http://www.youtube.com/player_api/",
        dataType: "script",
        success: function(data) {
            //if (isShuffle) {
                loadPlayer(global_video_id);
            //}
        },
        error: function(xhr, status, thrown) {
            fGetScript();
        }
    });
}
function loadVideoByVideoId(videoID) {
    player.loadVideoById(videoID);
}
var player = {
  playVideo: function(container, videoId) {
    if (typeof(YT) == 'undefined' || typeof(YT.Player) == 'undefined') {
      window.onYouTubeIframeAPIReady = function() {
        player.loadPlayer(container, videoId);
      };

      $.getScript('//www.youtube.com/iframe_api');
    } else {
      player.loadPlayer(container, videoId);
    }
  },

  loadPlayer: function(container, videoId) {
    new YT.Player(container, {
      videoId: videoId,
      playerVars: {
        autoplay: 1,
        controls: 1,
        autoplay: 1,
        enablejsapi: 1,
        allowScriptAccess: "always",
        modestbranding: 1,
        rel: 1,
        showInfo: 1
      }
    });
  }
};
function loadPlayer(videoID) {

    player = new YT.Player(
    'player', {
        videoId: videoID, 
        events: {
            "onStateChange": onPlayerStateChange 
        },
        playerVars: {
            "rel": 1, // 関連動画の有無(default:1)
            "showinfo": 0, // 動画情報表示(default:1)
            "controls": 1, // コントロール有無(default:1)
            "autoplay": 1,
            "enablejsapi": 1,
            "allowScriptAccess": "always"
        }
    }
);
    $("#player_area").html(player.getIframe());
}
function onPlayerStateChange(event) {
    if (event.data == 0) {
        //shuffle();
    }
}
function dbg(str) {
    $("#debuglog").val(str + "\n" + $("#debuglog").val());
    if (window.console && window.console.log) {
        console.log(str);
    }
}
function _run() {
    initloadPlayer();
}
function loadBodyAction(){
    return;
}
window.onYouTubeIframeAPIReady = function() {
    loadPlayer(global_video_id);
}
google.setOnLoadCallback(_run);
</script>
</head>
<body onload="loadBodyAction();">
<div  id="main_box" data-role="page"  >
<div data-role="header">
<h3>player</h3>
</div>
<div id="main_content" data-role="content" >

<div id="palyer_wrapper" >
<table class="player_table" align="center">
<tr>
    <td><div id="player_area" ><div id="videoDiv" ></div><div id='player' ></div></div>
    </td><td align="left"><div id="videoInfo"></div></td>
</tr>
</table>
</div>
</div><!--player_area-->
<div data-role="footer" >
<div data-role="navbar">
<ul>
<li><a href="/ranking.php">home</a></li>
</ul>
</div>
</div>

</div><!--page-->
</body>
</html>